package model

import (
	"github.com/astaxie/beego"
	"nspel/entity"
)

type GetReportPackageListAdministrator struct {
	ProvinceId  int64
	CityId      int64
	AreaId      int64
	SchoolName  string
	JoinYear    int64
	PageSize    int64
	CurrentPage int64
}

func (getReportPackageListAdministrator *GetReportPackageListAdministrator) Validate(provinceId string, cityId string, areaId string, schoolName string, joinYear string, pageSize string, currentPage string, c *beego.Controller) bool {
	var err error
	getReportPackageListAdministrator.ProvinceId, err = c.GetInt64(provinceId)
	if err != nil {
		return false
	}
	getReportPackageListAdministrator.CityId, err = c.GetInt64(cityId)
	if err != nil {
		return false
	}
	getReportPackageListAdministrator.AreaId, err = c.GetInt64(areaId)
	if err != nil {
		return false
	}
	getReportPackageListAdministrator.SchoolName = c.GetString(schoolName)
	getReportPackageListAdministrator.JoinYear, err = c.GetInt64(joinYear)
	if err != nil {
		return false
	}
	getReportPackageListAdministrator.PageSize, err = c.GetInt64(pageSize)
	if err != nil {
		return false
	}
	getReportPackageListAdministrator.CurrentPage, err = c.GetInt64(currentPage)
	if err != nil {
		return false
	}
	return true
}

type GetReportPackageListArea struct {
	JoinYear    int64
	SchoolId    int64
	PageSize    int64
	CurrentPage int64
}

func (getReportPackageListArea *GetReportPackageListArea) Validate(joinYear string, schoolId string, pageSize string, currentPage string, c *beego.Controller, uid int64) (bool, error) {
	var err error
	getReportPackageListArea.JoinYear, err = c.GetInt64(joinYear)
	if err != nil {
		return false, nil
	}
	getReportPackageListArea.SchoolId, err = c.GetInt64(schoolId)
	if err != nil {
		return false, nil
	}
	getReportPackageListArea.PageSize, err = c.GetInt64(pageSize)
	if err != nil {
		return false, nil
	}
	getReportPackageListArea.CurrentPage, err = c.GetInt64(currentPage)
	if err != nil {
		return false, nil
	}
	if getReportPackageListArea.SchoolId != 0 {
		school := new(entity.School)
		err = school.SelectAllById(getReportPackageListArea.SchoolId)
		if err != nil {
			return false, err
		}
		area := new(entity.Area)
		err = area.SelectAllById(school.ExperimentAreaId)
		if err != nil {
			return false, err
		}
		if area.UserId.Int64 != int64(uid) {
			return false, nil
		}
	}
	return true, nil
}
